﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Server.Models;
using Server.AuthService;

namespace Server.AuthManage
{
    public class AuthBLL
    {
        AuthDAL aDal = new AuthDAL();
        public bool CheckAuth(int id ,string key)
        {
            try
            {
                return aDal.CheckAuth(id, key);
            }
            catch (Exception)
            {
                throw;
            }
        }
        /// <summary>
        /// 获取权限列表
        /// </summary>
        public AuthListModel[] GetAuthCate()
        {
            try
            {
                AuthListModel[] al = aDal.GetAuthCate();
                return al;
            }
            catch (Exception)
            {
                throw;
            }
        }
        /// <summary>
        /// 获取用户对应权限
        /// </summary>
        /// <param name="uid"></param>
        /// <returns></returns>
        public AuthorModel[] GetAuthorList(int uid)
        {
            try
            {
                if (0 == uid)
                    throw new Exception("用户ID错误！");
                AuthorModel[] am = aDal.GetAuthorList(uid);
                return am;
            }
            catch (Exception)
            {

                throw;
            }
        }

        /// <summary>
        /// 保存权限
        /// </summary>
        /// <param name="author">用户权限对应模型数组</param>
        public void SaveAuthorInfo(AuthorModel[] author)
        {
            try
            {
                if (null == author)
                    throw new Exception("错误数据！");
                aDal.SaveAuthorInfo(author);
            }
            catch (Exception)
            {
                throw;
            }
        }
    }
}
